/*
ADC related code for the AC motor controller
*/

#include <p30F4011.h>
#include "settings.h"
#include "AC-Controller.h"
#include "globals.h"

//---------------------------------------------------------------------
// The ADC sample and conversion is triggered by the PWM period.
//---------------------------------------------------------------------
// Since this is an interrupt handler we've got to do what we came here to do
//and get the *%#% out of dodge
void __attribute__ ((__interrupt__)) __attribute__((no_auto_psv)) _ADCInterrupt(void) {
    IFS0bits.ADIF = 0;  	// Interrupt Flag Status Register. Pg. 142 in F.R.M.
							// ADIF = A/D Conversion Complete Interrupt Flag Status bit.  
							// ADIF = 0 means we are resetting it so that an interrupt request has not occurred.

//These three always come through. They've the most important
	i_alpha = ADCBUF1;  // AN0
	i_b = ADCBUF2;  // AN1
	hv_raw_input = ADCBUF3; //AN2			

//Now, the stuff we don't care about so much. This includes the two throttle values and
//the motor temperature. We've got to read in which ever we last told the ADC we wanted
//and then increment to the next value we're interested in and tell the ADC to set up for
//that one.

//but, for now just read in the first throttle value
	throttle_raw = ADCBUF0; //AN6

}
